﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GsOrganization.Common.Helper
{
    /// <summary>
    /// 哈希处理帮助类
    /// </summary>
    public class HashHandleHepler
    {
        /// <summary>
        /// 使用 SHA256 哈希算法对消息和时间戳进行哈希处理
        /// </summary>
        /// <param name="bsMessage"></param>
        /// <param name="bsTimeStamp"></param>
        /// <returns></returns>
        public static byte[] SHA256(byte[] bsMessage, byte[] bsTimeStamp)
        {
            if (bsMessage == null || bsTimeStamp == null)
            {
                return Array.Empty<byte>();
            }
            // 合并消息和时间戳
            byte[] combined = new byte[bsMessage.Length + bsTimeStamp.Length];
            Buffer.BlockCopy(bsMessage, 0, combined, 0, bsMessage.Length);
            Buffer.BlockCopy(bsTimeStamp, 0, combined, bsMessage.Length, bsTimeStamp.Length);
            using (var sha256 = System.Security.Cryptography.SHA256.Create())
            {
                return sha256.ComputeHash(combined);
            }
        }
    }
}
